#coding=utf-8
import pymysql

def main():
    conn = pymysql.connect(host='39.98.165.236',port=3306,
                           user='root',password='123456',
                           database='hrs',charset='utf8')
    try:
        with conn.cursor() as cursor:
            result = cursor.execute(
                'insert into  tb_dept values(100,"销售2部","重庆")'
            )
            if result == 1:
                print('添加成功')
            conn.commit()
    except pymysql.MySQLError as error:
        print(error)
        conn.rollback()
    finally:
        conn.close()
    print(conn)

if __name__ == '__main__':
    main()